
//
//  ConsultCell.m
//  soccer
//
//  Created by 上官千城 on 15/9/4.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "ConsultCell.h"

@implementation ConsultCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self && [reuseIdentifier isEqualToString:@"consultCell"]) {
        [self creatCell];
    }
    if (self && [reuseIdentifier isEqualToString:@"CommentCell"]) {
        [self creatCommentCell];
    }
    if (self && [reuseIdentifier isEqualToString:@"RightCommentCell"]) {
        [self creatCommentCell];
    }
    return self;
}
//创建评论Cell
-(void)creatCommentCell
{//热门评论
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 60, 20)];
    label.text = @"热门评论";
    label.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:label];
    //line
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(label.frame.origin.x + label.frame.size.width +10, 8, WIDTH, 1)];
    line.alpha = 0.2;
    line.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:line];
    //热点评论者头像
    self.hotUserimage = [[UIImageView alloc]initWithFrame:CGRectMake(40, 30, 40, 40)];
    self.hotUserimage.layer.masksToBounds = YES;
    self.hotUserimage.layer.cornerRadius = 20;
    self.hotUserimage.userInteractionEnabled = YES;
    [self.contentView addSubview:self.hotUserimage];
    //热点评论轻怕
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapACtion:)];
    [self.hotUserimage addGestureRecognizer:tap];
    //热点评论者昵称
    self.hotUserName = [[UILabel alloc]initWithFrame:CGRectMake(self.hotUserimage.frame.origin.x+self.hotUserimage.frame.size.width+10, self.hotUserimage.frame.origin.y, WIDTH/2, 20)];
//    self.hotUserName.text = @"西班大牙";
//    self.hotUserName.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.hotUserName];
    //热点评论者时间
    self.hotUserTime = [[UILabel alloc]initWithFrame:CGRectMake(self.hotUserName.frame.origin.x, self.hotUserName.frame.origin.y+self.hotUserName.frame.size.height, 100, 20)];
    self.hotUserTime.text = @"12月31日";
    self.hotUserTime.textColor = [UIColor lightGrayColor];
    self.hotUserTime.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.hotUserTime];
    //热点评论者点赞
    self.hotGood = [UIButton buttonWithType:UIButtonTypeCustom];
    self.hotGood.frame = CGRectMake(WIDTH - 50, self.hotUserName.frame.origin.y, 40, 40);
    [self.hotGood setImage:[UIImage imageNamed:@"manpage_15@2x"] forState:UIControlStateNormal];
    [self.hotGood addTarget:self action:@selector(hotGoodAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.hotGood];
    //热点评论者正文
    self.hotText = [[UILabel alloc]initWithFrame:CGRectMake(self.hotUserTime.frame.origin.x, self.hotUserTime.frame.origin.y+self.hotUserTime.frame.size.height, WIDTH - self.hotUserimage.frame.size.width - 60, 30)];
//    self.hotText.backgroundColor = [UIColor orangeColor];
    self.hotText.numberOfLines = 0;
    [self.contentView addSubview:self.hotText];
    //其他评论者底层View
//    self.textView = [[UIView alloc]initWithFrame:CGRectMake(self.hotText.frame.origin.x, 250, self.hotText.frame.size.width, 200)];
//    self.textView.backgroundColor = RGBACOLOR(237, 236, 239, 1);
//    [self.contentView addSubview:self.textView];
//    //评论者A头像
//    self.userImageA = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, self.hotUserimage.frame.size.width, self.hotUserimage.frame.size.height)];
//    self.userImageA.layer.masksToBounds = YES;
//    self.userImageA.layer.cornerRadius = 20;
//    [self.textView addSubview:self.userImageA];
//    //评论者A昵称
//    self.userNameA = [[UILabel alloc]initWithFrame:CGRectMake(self.userImageA.frame.origin.x+self.userImageA.frame.size.width+5, self.userNameA.frame.origin.y+5, 200, 20)];
//    [self.textView addSubview:self.userNameA];
//    //评论者A时间
//    self.userTimeA = [[UILabel alloc]initWithFrame:CGRectMake(self.userNameA.frame.origin.x, self.userNameA.frame.origin.y + self.userNameA.frame.size.height, 100, 20)];
//    self.userTimeA.textColor = [UIColor lightGrayColor];
//    self.userTimeA.font = [UIFont systemFontOfSize:14];
//    self.userTimeA.text = @"12月31日";
//    [self.textView addSubview:self.userTimeA];
//    //评论者A点赞
//    self.userGoodA = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.userGoodA setImage:[UIImage imageNamed:@"manpage_15"] forState:UIControlStateNormal];
//    self.userGoodA.frame = CGRectMake(self.textView.frame.size.width - 40, self.userImageA.frame.origin.y-5, 30, 30);
//    [self.userGoodA addTarget:self action:@selector(userGoodAbutton) forControlEvents:UIControlEventTouchUpInside];
//    [self.textView addSubview:self.userGoodA];
//    //A点赞数量
//    self.goodNumA = [[UILabel alloc]initWithFrame:CGRectMake(self.userGoodA.frame.origin.x-5, self.userGoodA.frame.origin.y + self.userGoodA.frame.size.height-5 , 50, 20)];
//    self.goodNumA.text = @"123456";
//    self.goodNumA.textColor = [UIColor lightGrayColor];
//    self.goodNumA.font = [UIFont systemFontOfSize:12];
//    [self.textView addSubview:self.goodNumA];
//    //A正文
//    self.textA = [[UILabel alloc]initWithFrame:CGRectMake(self.userNameA.frame.origin.x, self.userNameA.frame.origin.y + self.userNameA.frame.size.height+10, self.textView.frame.size.width - self.userImageA.frame.size.width-10, 60)];
//    self.textA.numberOfLines = 0;
//    [self.textView addSubview:self.textA];
//    //B头像
//    self.userImageB = [[UIImageView alloc]initWithFrame:CGRectMake(self.userImageA.frame.origin.x, self.textA.frame.origin.y + self.textA.frame.size.height+ 5, self.userImageA.frame.size.width, self.userImageA.frame.size.height)];
//    self.userImageB.layer.masksToBounds = YES;
//    self.userImageB.layer.cornerRadius = 20;
//    [self.textView addSubview:self.userImageB];
//    //B昵称
//    self.userNameB = [[UILabel alloc]initWithFrame:CGRectMake(self.userImageB.frame.origin.x + self.userImageB.frame.size.width+5, self.userImageB.frame.origin.y, self.userNameA.frame.size.width, self.userNameA.frame.size.height)];
//    [self.textView addSubview:self.userNameB];
//    //B时间
//    self.userTimeB = [[UILabel alloc]initWithFrame:CGRectMake(self.userNameB.frame.origin.x, self.userNameB.frame.origin.y + self.userNameA.frame.size.height, 100, 20)];
//    self.userTimeB.textColor = [UIColor lightGrayColor];
//    self.userTimeB.font = [UIFont systemFontOfSize:14];
//    self.userTimeB.text = @"12月31日";
//    [self.textView addSubview:self.userTimeB];
//    //评论者A点赞
//    self.userGoodB = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.userGoodB setImage:[UIImage imageNamed:@"manpage_15"] forState:UIControlStateNormal];
//    self.userGoodB.frame = CGRectMake(self.textView.frame.size.width - 40, self.userImageB.frame.origin.y-5, 30, 30);
//    [self.userGoodB addTarget:self action:@selector(userGoodBbutton) forControlEvents:UIControlEventTouchUpInside];
//    [self.textView addSubview:self.userGoodB];
//    //B点赞数量
//    self.goodNumB = [[UILabel alloc]initWithFrame:CGRectMake(self.userGoodB.frame.origin.x-5, self.userGoodB.frame.origin.y + self.userGoodB.frame.size.height-5 , 50, 20)];
//    self.goodNumB.text = @"123456";
//    self.goodNumB.textColor = [UIColor lightGrayColor];
//    self.goodNumB.font = [UIFont systemFontOfSize:12];
//    [self.textView addSubview:self.goodNumB];
//    //B正文
//    self.textB = [[UILabel alloc]initWithFrame:CGRectMake(self.userNameB.frame.origin.x, self.userNameB.frame.origin.y + self.userNameB.frame.size.height+10, self.textView.frame.size.width - self.userImageB.frame.size.width-10, 60)];
//    self.textB.numberOfLines = 0;
//    [self.textView addSubview:self.textB];

}
//B评论者 点赞
-(void)userGoodBbutton
{
    NSLog(@"B");
}
//评论者A点赞
-(void)userGoodAbutton
{
    NSLog(@"A");
}

//热点评论者点赞方法
-(void)hotGoodAction
{
    NSLog(@"dianzan");

}

//创建资讯Cell
-(void)creatCell
{//媒体图片
    self.head = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 60, 60)];
//    self.head.backgroundColor = [UIColor orangeColor];
    self.head.userInteractionEnabled = YES;
    self.head.layer.masksToBounds = YES;
    self.head.layer.cornerRadius = 10;
    [self.contentView addSubview:self.head];
    //轻拍手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headButton)];
    [self.head addGestureRecognizer:tap];
    //标题
    self.titile = [[UILabel alloc]initWithFrame:CGRectMake(self.head.frame.origin.x + self.head.frame.size.width + 10, self.head.frame.origin.y, WIDTH - self.head.frame.size.width - 30, 40)];
    self.titile.font = [UIFont boldSystemFontOfSize:18];
    self.titile.numberOfLines = 0;
//    self.titile.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.titile];
    //咨询正文
    self.massage = [[UILabel alloc]initWithFrame:CGRectMake(self.titile.frame.origin.x, self.titile.frame.origin.y+self.titile.frame.size.height + 5, self.titile.frame.size.width, 60)];
    self.massage.numberOfLines = 0;
//    self.massage.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:self.massage];
    //发表时间
    self.timed = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH - 70, self.titile.frame.origin.y+self.titile.frame.size.height-5, 60, 20)];
//    self.timed.backgroundColor = [UIColor blackColor];
    self.timed.font = [UIFont systemFontOfSize:14];
    self.timed.textColor = [UIColor lightGrayColor];
    self.timed.text = @"12月31日";
    [self.contentView addSubview:self.timed];
    //热度图片
    self.hotImage = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH - self.timed.frame.size.width - 40, self.timed.frame.origin.y, 20, 20)];
//    self.hotImage.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.hotImage];
    //咨询图片1
    self.img1 = [[UIImageView alloc]initWithFrame:CGRectMake(self.titile.frame.origin.x, self.massage.frame.origin.y + self.massage.frame.size.height+5, self.contentView.frame.size.width / 4, self.contentView.frame.size.width/4)];
//    self.img1.backgroundColor = [UIColor orangeColor];
    self.img1.image = [UIImage imageNamed:@"402"];
    self.img1.userInteractionEnabled = YES;
    [self.contentView addSubview:self.img1];
    //图片1手势
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap1Action)];
    [self.img1 addGestureRecognizer:tap1];
    //咨询图片2
    self.img2 = [[UIImageView alloc]initWithFrame:CGRectMake(self.img1.frame.origin.x + self.img1.frame.size.width+10, self.img1.frame.origin.y , self.contentView.frame.size.width / 4, self.contentView.frame.size.width/4)];
//    self.img2.backgroundColor = [UIColor orangeColor];
    self.img2.image = [UIImage imageNamed:@"403"];
    self.img2.userInteractionEnabled = YES;
    [self.contentView addSubview:self.img2];
    //图片2手势
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap2Action)];
    [self.img2 addGestureRecognizer:tap2];
    //咨询图片3
    self.img3 = [[UIImageView alloc]initWithFrame:CGRectMake(self.img2.frame.origin.x + self.img2.frame.size.width+10, self.img2.frame.origin.y, self.contentView.frame.size.width / 4, self.contentView.frame.size.width/4)];
//    self.img3.backgroundColor = [UIColor orangeColor];
    self.img3.image = [UIImage imageNamed:@"401"];
    self.img3.userInteractionEnabled = YES;
    [self.contentView addSubview:self.img3];
    //图片3手势
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap3Action)];
    [self.img3 addGestureRecognizer:tap3];
    //咨询
    
//    self.high = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.high.frame = CGRectMake(WIDTH - 50, self.contentView.frame.size.height+10 , 20, 20);
//    [self.high addTarget:self action:@selector(highButton) forControlEvents:UIControlEventTouchUpInside];
//    self.high.backgroundColor = [UIColor cyanColor];
//    [self.contentView addSubview:self.high];
//    
//    self.low = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.low.frame = CGRectMake(self.high.frame.origin.x + self.high.frame.size.width + 5, self.high.frame.origin.y, self.high.frame.size.width, self.high.frame.size.height);
//    self.low.backgroundColor = [UIColor brownColor];
//    [self.low addTarget:self action:@selector(lowButton) forControlEvents:UIControlEventTouchUpInside];
//    [self.contentView addSubview:self.low];
//    
    
}
//点击个人头像事件
-(void)tapACtion:(UITapGestureRecognizer *)tap
{
    [self.myDelegate pushPerson];
}
//点击咨询图片1
-(void)tap1Action
{
    [self.imgDelegate1 bringIm1:self.con];
}
//点击咨询图片2
-(void)tap2Action
{
    [self.imgDelegate2 bringIm2];
}
//点击咨询图片3
-(void)tap3Action
{
    [self.imgDelegate3 bringIm3];
}
//资讯赋值重写model set方法
-(void)setCon:(Consult *)con
{
    if (_con != con) {
        _con = con;
        self.titile.text = con.title;
        self.massage.text = con.preview;
//        self.timed.text = con.date;
        NSString *str = con.image;
        NSURL *url = [NSURL URLWithString:str];
        [self.head sd_setImageWithURL:url];
        [self.img1 sd_setImageWithURL:url];
        [self.img2 sd_setImageWithURL:url];
        [self.img3 sd_setImageWithURL:url];
//        NSLog(@"%@",con.title);
    }
}
//评论赋值重写model set方法
-(void)setCom:(concom *)com
{
    if (_com != com) {
        _com = com;
        NSString *str = com.answerAccountPic;
        NSURL *url = [NSURL URLWithString:str];
        [self.hotUserimage sd_setImageWithURL:url];
        self.hotText.text = com.answerIntro;
        self.hotUserName.text = com.accountName;
        [self.hotText sizeToFit];
        [self.userImageA sd_setImageWithURL:url];
        [self.userImageB sd_setImageWithURL:url];
        self.userNameA.text = com.accountName;
        self.userNameB.text = com.accountName;
        self.textA.text = com.answerIntro;
        self.textB.text = com.answerIntro;
    }
}

-(void)highButton
{
    NSLog(@"high");
}

-(void)lowButton
{
    NSLog(@"low");
}
//资讯媒体头像
-(void)headButton
{
    NSLog(@"个人");
    [self.myDelgate pushMP4];
}



@end
